<template>
  <div class="page-container">
    <!-- 固定头部 -->
    <header class="header">
      <div class="header-content">
        <!-- 左侧logo -->
        <div class="logo" @click="toIndex()">
          <img
            class="image_top"
            referrerpolicy="no-referrer"
            src="./assets/img/top.png"
          />
        </div>

        <!-- 右侧按钮 -->
        <div class="header-actions">
          <el-button class="login_btn1 my_btn" @click="toAccount" v-if="name != null && name != ''">My Account
          </el-button>
          <el-button class="login_btn my_btn" @click="tologin" v-if="name == null || name == ''">Login</el-button>
          <el-button class="postads_btn" @click="postAds">Post&nbsp;Ads</el-button>
        </div>
      </div>
    </header>

    <!-- 可滚动内容区域 -->
    <main class="main-content">
      <div class="content">
        <!--   查询条件   -->
        <div class="box_1 flex-row">
          <el-select v-model="category" class="search1" placeholder="Please Select">
            <el-option v-for="category in categorys" :label="category.name" :value="category.id" :key="category.id"/>
          </el-select>
          <el-select
            class="search1"
            v-model="city"
            filterable
            remote
            reserve-keyword
            placeholder="City name"
            :remote-method="remoteMethod"
            :loading="loading">
            <el-option
              v-for="item in options"
              :key="item.value"
              :label="item.label"
              :value="item.value">
            </el-option>
          </el-select>
          <el-input class="search1" v-model="query" placeholder="Enter query"></el-input>

          <el-button class="search2" style="margin-left: auto;margin-right: 5px;" @click="search">Search</el-button>
        </div>

        <div class="box_2 flex-row">
          <img
            class="thumbnail_2"
            referrerpolicy="no-referrer"
            src="./assets/img/home.png"
          />
          <el-breadcrumb separator="/">
            <el-breadcrumb-item :to="{ path: '/' }">Home</el-breadcrumb-item>
<!--            <el-breadcrumb-item>
              {{ viewInfo }}
            </el-breadcrumb-item>-->
            <el-breadcrumb-item :to="{ path: '/cmsIndex2?zhou=' + viewInfo1 }">
              {{ viewInfo1 }}
            </el-breadcrumb-item>
            <el-breadcrumb-item :to="{ path: '/cmsIndex3?zhou=' + viewInfo1 + '&city=' + viewInfo2 }">
              {{ viewInfo2 }}
            </el-breadcrumb-item>
            <el-breadcrumb-item>
              {{ viewInfo3 }}
            </el-breadcrumb-item>
          </el-breadcrumb>
        </div>

        <!-- 这里放置你的页面主要内容 -->
        <div class="center_content">

          <div class="friendList">
            Friend List
          </div>
          <!-- 右上角切换按钮组 -->
          <div class="view-switcher">
            <el-button-group>
              <el-button
                @click="toggleView('card')"
                icon="el-icon-menu"
                :autofocus="true"
              ></el-button>
              <el-button
                @click="toggleView('list')"
                icon="el-icon-s-fold"
              ></el-button>
            </el-button-group>
          </div>


          <!-- 普通列表 -->
          <div v-if="isList" style="margin-top: 50px;">
            <ul class="list">
              <li v-for="(item, key) in paginatedData" :key="key">
                <router-link v-if="item.highlightMode == 0" :to="'/cmsDetail?id=' + item.id"
                             style="color: black; font-size: 14px;">
                  {{ item.title }}
                  <img v-if="item.topMode == 1" src="./assets/img/hot.gif"></img>
                </router-link>
                <router-link v-if="item.highlightMode == 1" :to="'/cmsDetail?id=' + item.id"
                             style="color: red; font-size: 14px; font-weight: 600">
                  {{ item.title }}
                  <img style="height: 15px;width: 35px; margin-bottom: -2px" v-if="item.topMode == 1" src="./assets/img/hot.gif"></img>
                </router-link>
                <br>
                <span style="font-size: 12px; color: grey">{{ item.createTime }}</span>
                <hr>
              </li>
            </ul>

            <div style="text-align: center; margin-top: 20px;">
              <el-pagination
                @current-change="handlePageChange"
                :current-page="pagination.currentPage"
                :page-size="pagination.pageSize"
                layout="prev, pager, next"
                :total="tableData.length">
              </el-pagination>
            </div>
          </div>
          <!-- 卡片列表 -->
          <div v-if="!isList" style="margin-top: 50px;">
            <div class="image-grid-container">
              <div
                v-for="(item, index) in paginatedData"
                :key="index"
                class="image-item"
                @click="handleButtonClick2(item.$index, item.id)"
              >
                <img v-if="item.filePath == null || item.filePath == ''" src="./assets/img/girl.png" class="grid-image">
                <img v-else :src="item.filePath" class="grid-image">

                <!-- 左上角标签 -->
                <div class="top-left-label" v-if="item.topMode == 1">
                  <img class="hot-display" src="./assets/img/hot.gif"></img>
                </div>

                <!-- 底部描述 -->
                <div class="bottom-description" v-if="item.highlightMode == 0">
                  {{ formatPhoneNumber(item.phone) }}/{{item.age}}
                </div>

                <div class="bottom-description-height" v-if="item.highlightMode == 1">
                  {{ formatPhoneNumber(item.phone) }}/{{item.age}}
                </div>

              </div>
            </div>
            <div style="text-align: center; margin-top: 20px;">
              <el-pagination
                @current-change="handlePageChange"
                :current-page="pagination.currentPage"
                :page-size="pagination.pageSize"
                layout="prev, pager, next"
                :total="dataList.length">
              </el-pagination>
            </div>
          </div>
        </div>
      </div>
    </main>

    <!-- 固定底部 -->
    <footer class="footer">
      <div class="footer1">Terms｜About&nbsp;us｜Contact&nbsp;us｜Privacy</div>
      <div class="footer1">Email:topgirlspage88@gmail.com</div>
      <hr>
      <div class="footer1">Copyright&nbsp;©&nbsp;2025&nbsp;topgirlspage.com&nbsp;All&nbsp;Rights&nbsp;Reserved</div>
    </footer>

    <!--  弹窗提示  -->
    <el-dialog title="Publisth ad rules" :visible.sync="outerVisible">
      Before the topgirlspage.com writes the advertisement
      You agree to follow these rules:
      <br>
      1.All posters must be of legal age.
      <br>
      2.You may not post any content or information of anyone that is not of legal age.
      <br>
      3.You may not mention or infer that any person advertised is of less than legal age. Words like "young", "school
      girl-like" or similar may not be used.
      <br>
      4.You may not post images or personal information of another person without consent.
      <br>
      5.It is forbidden to publish any pictures and words involving nudity, genitalia, violence, drugs, guns, child
      trafficking and women. Once found, the account will be deleted and IP login will be permanently closed
      <div slot="footer" class="dialog-footer">
        <el-button @click="outerVisible = false">Cancle</el-button>
        <el-button type="primary" @click="toPublish">I Agree</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {mapGetters} from "vuex";
import {getCityAndZhou} from "@/api/cms/city";
import {list, topList} from "@/api/cms/ad";

export default {
  data() {
    return {
      imageList: Array(30).fill().map((_, i) => ({
        src: `https://picsum.photos/id/${i + 1}/600/900`, // 示例图片（6:9比例）
        alt: `Image ${i + 1}`
      })),
      viewInfo: '',
      viewInfo1: '',
      viewInfo2: '',
      viewInfo3: '',
      //name: '',
      isList: false,
      tableData: [],
      pagination: {
        currentPage: 1,
        pageSize: 30, // 五行六列，每页最多展示 5 * 6 = 30 个项目
        total: 0
      },
      form: {
        category: '',
        city: '',
        other: ''
      },
      citys: [],
      dataList: [], // 假设这个数组是你的数据源
      tops: [],
      options: [],
      // value: [],
      loading: false,
      category: '',
      city: '',
      query: '',
      //province: [],
      categorys: [{
        id: 2,
        name: 'Bodyrubs'
      }, {
        id: 3,
        name: 'Escorts'
      }, {
        id: 4,
        name: 'All'
      }],
      outerVisible: false,
      imgPrefix: process.env.VUE_APP_BASE_API
    };
  },
  methods: {
    toIndex() {
      this.$router.push({
        path: "/cms/main/cmsIndex"
      });
    },
    list() {
      // const { currentPage, pageSize } = this.pagination
      try {
        // 调用API获取分页数据
        // const response = await this.$api.getData({
        //   page: currentPage,
        //   size: pageSize
        // })
        // this.tableData = response.data.list
        // this.pagination.total = response.data.total
      } catch (error) {
      }
    },
    search() {
      this.form.pageNum = 1
      this.form.pageSize = 30
      this.form.category = parseInt(this.category)
      this.form.city = this.city
      this.form.other = this.query
      if (!this.form.category) {
        this.form.category = 4
      }
      // 查询分页列表
      this.firendList()
    },
    toggleView(type) {
      if (type === 'card') {
        this.isList = false;
      }
      if (type === 'list') {
        this.isList = true;
      }

    },
    //电话格式化
    formatPhoneNumber(phone) {
      if (!phone) return '';
      // 移除所有非数字字符
      const cleaned = phone.replace(/\D/g, '');
      // 3-4-4格式分割
      const match = cleaned.match(/^(\d{3})(\d{4})(\d{4})$/);
      return match ? `${match[1]}-${match[2]}-${match[3]}` : phone;
    },
    // 行点击，进入详细
    handleButtonClick(index, row) {
      this.$router.push({path: "/cmsDetail?id=" + row.id});
      // 阻止事件冒泡后，不会触发 row-click 事件
    },
    handleButtonClick2(index, id) {
      this.$router.push({path: "/cmsDetail?id=" + id});
      // 阻止事件冒泡后，不会触发 row-click 事件
    },
    firendList() {
      list(this.form).then(res => {
        var arr = new Array()
        for (let i = 0; i < res.rows.length; i++) {
          if (res.rows[i].fileInfos != null && res.rows[i].fileInfos.length > 0) {
            // 测试
            //res.rows[i].filePath = "/dev-api/" + res.rows[i].fileInfos[0].filePath
            // 服务器
            res.rows[i].filePath = this.imgPrefix + res.rows[i].fileInfos[0].filePath
          }
          arr.push(res.rows[i])
        }
        this.tableData = arr
      })
    },
    handlePageChange(page) {
      this.pagination.currentPage = page;
    },
    remoteMethod(query) {
      if (query !== '') {
        this.loading = true;
        setTimeout(() => {
          this.loading = false;
          this.options = this.list.filter(item => {
            return item.label.toLowerCase().indexOf(query.toLowerCase()) > -1;
          });
        }, 200);
      } else {
        this.options = [];
      }
    },
    toSearch() {
      this.$router.push({
        path: "/list?category=" + this.category + "&city=" + this.city + "&query=" + this.query
      });
    },
    postAds() {
      this.outerVisible = true
    },
    toPublish() {
      this.$router.push({
        path: "/cmsPublish"
      });
    },
    tologin() {
      this.$router.push({
        path: "/cmsLogin"
      });
    },
    toAccount() {
      this.$router.push({
        path: "/cmsAcount"
      });
    },
    getCityAndZhou() {
      getCityAndZhou().then(res => {
        this.list = res.data.map(item => {
          return {value: `${item.zhouName}`, label: `${item.zhouName}`};
        })
      });
    }
  },
  created() {
    this.getCityAndZhou()
    var category = this.$route.query.category
    var city = this.$route.query.city
    var query = this.$route.query.query
    this.form.category = parseInt(category)
    this.form.city = city
    this.form.other = query
    // 计算头部显示
    var arrCitys = city.split(",")
    if (arrCitys.length == 2) {
      this.viewInfo += arrCitys[0] + " - "+ arrCitys[1] + " - "
      this.viewInfo2 = arrCitys[0]
      this.viewInfo1 = arrCitys[1]
    }
    if (category == '2') {
      this.viewInfo += "Body Rub"
      this.viewInfo3 = "Body Rub"
    } else if (category == '3') {
      this.viewInfo += "Escort"
      this.viewInfo3 = "Escort"
    }
    // 查询分页列表
    this.form.pageNum = 1
    this.form.pageSize = 30

    this.firendList()
  },
  computed: {
    ...mapGetters([
      'name'
    ]),
    paginatedData() {
      const start = (this.pagination.currentPage - 1) * this.pagination.pageSize
      const end = start + this.pagination.pageSize
      console.log(this.tableData.slice(start, end))
      return this.tableData.slice(start, end)
    }
  },
}
</script>

<style scoped>
.image-grid-container {
  display: grid;
  grid-template-columns: repeat(5, 1fr); /* 5列 */
  gap: 10px; /* 固定间隔10px */
  width: 100%;
  padding: 10px; /* 可选：容器内边距 */
  box-sizing: border-box;
}

.image-item {
  position: relative;
  width: 100%;
  padding-top: 150%; /* 9/6 = 1.5 (即 150%) 保持6:9比例 */
  overflow: hidden;
}

.grid-image {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  object-fit: cover; /* 保持比例并填充容器 */
}

/* 左上角标签样式 */
.top-left-label {
  position: absolute;
  top: 10px;
  left: 10px;
  background-color: rgba(0, 0, 0, 0.5); /* 半透明黑色背景 */
  color: white;
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 12px;
  z-index: 1; /* 确保在图片上方 */
}

/* 底部描述样式 */
.bottom-description {
  position: absolute;
  bottom: 10px;
  left: 0;
  right: 0;
  background-color: rgba(0, 0, 0, 0.5); /* 半透明黑色背景 */
  color: white;
  padding: 8px;
  font-size: 22px;
  text-align: center;
  z-index: 1; /* 确保在图片上方 */
}

.bottom-description-height {
  position: absolute;
  bottom: 10px;
  left: 0;
  right: 0;
  background-color: rgba(0, 0, 0, 0.5); /* 半透明黑色背景 */
  color: #FFD716;
  font-weight: bold;
  padding: 8px;
  font-size: 22px;
  text-align: center;
  z-index: 1; /* 确保在图片上方 */
}

/* 新增图片容器样式 */
.image-container {
  position: relative;
  display: block;
  //width: 100%;
  width: 167px;
}

.phone-overlay .el-icon {
  margin-right: 5px;
  font-size: 18px;
}

.hot-display {
  position: absolute;
  top: 0;
  left: 0;
  width: 44px;
  height: 20px;
}

.phone-display {
  position: absolute;
  bottom: 0;
  left: 0;
  width: 100%;
  background: rgba(128, 128, 128, 0.5);
  padding: 8px 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.3s ease;
  color: yellow;
}

.phone-display1 {
  position: absolute;
  bottom: 0;
  left: 0;
  width: 100%;
  background: rgba(128, 128, 128, 0.5);
  padding: 8px 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.3s ease;
  color: red;
}

.phone-number {
  color: #cc14a1;
  font-weight: 600;
  font-size: 20px;
  letter-spacing: 0.5px;
}

.list {
  line-height: 34px;
  border-bottom: 1px solid #eee;
  font-size: 16px;
  a {
    color: #666;
  }
}

/* 卡片内容区域调整 */
.card-content {
  padding: 12px 15px;
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.card-header h3 {
  font-size: 16px;
  margin: 0;
  display: flex;
  align-items: center;
  flex-grow: 1;
}

/* 重置默认边距 */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

.page-container {
  display: flex;
  flex-direction: column;
  height: 100vh;
  width: 100%;
  overflow: hidden;
}

/* 头部样式 */
.header {
  height: 60px;
  background-color: white;
  color: white;
  padding: 0 20px;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}

.header-content {
  display: flex;
  justify-content: space-between;
  align-items: center;
  height: 100%;
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
}

.view-switcher {
  text-align: right;
  margin-bottom: 20px;
}

.image_top {
  width: 252px;
  height: 52px;
  margin: 8px 0 0 240px;
}

.header-actions {
  display: flex;
  gap: 15px;
}

.my_btn {
  height: 40px;
  background: linear-gradient(#FF3A90 0%, #C6044B 100%);
  border-radius: 6px;
  font-family: SourceHanSansCN, SourceHanSansCN;
  font-weight: 500;
  font-size: 16px;
  color: #FFFFFF;
  line-height: 24px;
  text-align: center;
  font-style: normal;
  margin: 8px 0 0 calc(100vw - 1000px);
}

.login_btn {
  width: 84px;
}

.login_btn1 {
  width: 140px;
}

.postads_btn {
  width: 105px;
  height: 40px;
  background: #2D1B0B;
  border-radius: 6px;
  font-family: SourceHanSansCN, SourceHanSansCN;
  font-weight: 500;
  font-size: 16px;
  color: #FBD798;
  line-height: 24px;
  text-align: center;
  font-style: normal;
  margin: 8px 0 0 8px;
}

/* 中间内容区域 */
.main-content {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  background-color: #FFF6F9;
}

.content {
  max-width: 1200px;
  margin: 0 auto;
}

.flex-row {
  display: flex;
  flex-direction: row;
}

.box_1 {
  max-width: 1200px;
  height: 52px;
  /*background: url(https://lanhu-oss-2537-2.lanhuapp.com/SketchPngf5d0297da7e4a7c3d534b43a2ea85fa403a16d5a578c427828027844f7782e13) 100% no-repeat;*/
  background: url(../cms/assets/img/search_bg.png) 100% no-repeat;
  background-size: 100% 100%;
  margin: 0 auto;
  justify-content: flex-start;
}

.box_2 {
  max-width: 1200px;
  height: 14px;
  font-size: 14px;
  margin: 10px 0px;
}

.thumbnail_2 {
  padding-right: 5px;
}

.search1 {
  width: calc(33vw - 40px);
  margin: auto 5px;
}

.search2 {
  width: 120px;
  height: 40px;
  text-align: center;
  margin: auto;
  color: #E81566;
  float: right;
}

.top-msg {
  margin: 8px 0;
  width: 100%;
  height: 52px;
  border-radius: 8px;
  border: 1px solid #E81566;
}

.card-image {
  width: 167px;
  height: 250px;
  object-fit: cover;
}

.friendList {
  width: 91px;
  height: 18px;
  font-family: SourceHanSansCN, SourceHanSansCN;
  font-weight: 500;
  font-size: 18px;
  color: #111111;
  line-height: 27px;
  text-align: left;
  font-style: normal;
}

.text-group_2 {
  width: 400px;
  height: 16px;
  font-weight: 500;
  font-size: 16px;
  line-height: 24px;
  text-align: left;
  font-style: normal;
  margin-top: 10px;
}

.text-group_1 {
  width: 100%;
  height: 16px;
  font-family: SourceHanSansCN, SourceHanSansCN;
  font-weight: 500;
  font-size: 16px;
  color: #E81566;
  line-height: 24px;
  text-align: left;
  font-style: normal;
  margin-top: 10px;
  margin-left: 20px;
}

/* 底部样式 */
.footer {
  height: 65px;
  background-color: #E81566;
  color: white;
  align-items: center;
  justify-content: center;
}

.footer1 {
  text-align: center;
  color: white;
  font-size: 14px;
  margin: 3px 0 0 0;
}
</style>
